		  
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Referred Commission</td>
  </tr>
  <tr>
      <td height="577">
	
	<div "style="overflow-y:scroll;"">
	<table width="100%"  border="0" cellspacing="0">      
      <tr class="InnerHeader">    
	   <td width="5%" class="line">Sln no.</td>   
        <td width="15%" class="line">Product</td>
		<td width="25%" class="line">Referred.User(Type) </td>
        <td width="25%" class="line">ReferredBy.User(Type)</td>
		<?php /*?><td width="10%" class="line">Ref.User(Merchant)</td>
		<td width="20%" class="line">User Who Referred</td><?php */?>
		<td width="15%" class="line">Transaction Amount</td>
		<td width="15%" class="line">Referred Comm</td>		
        </tr>
      
      <?php 
	  
	  			ini_set('display_errors', 1); 
				ini_set('error_reporting', 'E_error'); 
				 require_once "../includes/pagination.php";
				 $itemPerPage=10;
				 //$noOfColumns=0;
				 //date("Y-m-d",time());
				 $year=date("Y",time());
				 $month=date("m",time());
				 
				if (isset($_GET['page']) && (int)$_GET['page'] > 0) 
				{
				  $pageNumber = (int)$_GET['page'];		
				} 
				else 
				{
				  $pageNumber = 1;		
				}
				 //$sql_shocat1="SELECT b.user_type as ref_by_user_type FROM tbl_refer_comm r LEFT JOIN tbl_users u ON r.refer_to_user_id = u.user_id  left join tbl_users b ON r.refer_by_user_id = b.user_id WHERE DAYOFMONTH(buy_date)=".$month." AND EXTRACT(YEAR FROM buy_date)=".$year."  AND isPaid = '0' order BY refer_by_user_id";				 
				$sql_shocat="SELECT transaction_id,ref_comm_id,item_id,refer_comm,refer_to_user_id,refer_by_user_id,u.first_name as ref_first_name, u.last_name as ref_last_name,u.user_type as ref_user_type,b.first_name as ref_by_first_name, b.last_name as ref_by_last_name,b.user_type as ref_by_user_type FROM tbl_refer_comm r LEFT JOIN tbl_users u ON r.refer_to_user_id = u.user_id  left join tbl_users b ON r.refer_by_user_id = b.user_id  WHERE  (EXTRACT(MONTH FROM buy_date)=".$month." AND EXTRACT(YEAR FROM buy_date)=".$year.")  AND isPaid = '0' order BY refer_by_user_id desc";//limit ".$pageNumber.", ".$itemPerPage."";				 
				 $rst_comm=mysql_query($sql_shocat);
				 $row_comm=getRecordArray($rst_comm);
				 				 
				 //$rst_shocat=mysql_query(getPagingQuery($sql_shocat1,$itemPerPage));			
				 //$numRows = mysql_num_rows($rst_shocat);
				 $total=0;
				 if(is_array($row_comm))
				 {
				 	$counter=count($row_comm);
					for($i=0;$i<$counter;$i++)					
					{
					
					if($row_comm[$i]['ref_user_type']==1)
						$ref_type = "Buyer";
					else if($row_comm[$i]['ref_user_type']==2)
						$ref_type = "Seller";		 
					else if($row_comm[$i]['ref_user_type']==3)
						$ref_type = "Merchant";	
					else if($row_comm[$i]['ref_user_type']==4)
						$ref_type = "Seller/ Buyer";	
						
					if($row_comm[$i]['ref_by_user_type']==1)
						$ref_by_type = "Buyer";
					else if($row_comm[$i]['ref_by_user_type']==2)
						$ref_by_type = "Seller";		 
					else if($row_comm[$i]['ref_by_user_type']==3)
						$ref_by_type = "Merchant";	
					else if($row_comm[$i]['ref_by_user_type']==4)
						$ref_by_type = "Seller/ Buyer";	
						
						$sqlSelItem="select p.* from tbl_items i left join tbl_product p  on i.product_id=p.product_id where item_id=".$row_comm[$i]['item_id']."";
						$rstSelItem=mysql_query($sqlSelItem);
						$rowSelItem=mysql_fetch_array($rstSelItem);
						if(is_array($rowSelItem))
						{
							$product_name=$rowSelItem['product_name'];
						}
						
						$sqlSelItem="select * from tbl_orders where transaction_ID='".$row_comm[$i]['transaction_id']."'";
						$rstSelItem=mysql_query($sqlSelItem);
						$rowSelItem=mysql_fetch_array($rstSelItem);
						
						if(is_array($rowSelItem))
						{
							$order_amt=$rowSelItem['order_amount'];
						}
						
						$total=$total+$row_comm[$i]['refer_comm'];
					 			 
				 ?> 
					<tr>
					<td class="line"><?php echo ($i+1);?></td>
					<td class="line"><?php echo $product_name;?></td>
					<td class="line"><?php echo $row_comm[$i]['ref_first_name'].' '.$row_comm[$i]['ref_last_name'];?>(<?php echo $ref_type;?>)</td>
					<td class="line"><?php echo $row_comm[$i]['ref_by_first_name'].' '.$row_comm[$i]['ref_by_last_name'];?>(<?php echo $ref_by_type;?>)</td>					
					<td class="line">$<?php echo $order_amt;?></td>
					<td class="line">$<?php echo $row_comm[$i]['refer_comm'];?></td>			
					
      				</tr><?php } }?>     
       </table>
	<div align="center">
		<?php		   
		   $link="refer";
		   //echo $disp=getPagingLink($sql_shocat1,$itemPerPage,$link);							   
		?>    
	</div>
	</div>
	</td>
 </tr>
 <tr>
 <td style="text-align:right;">Total Owed so far $<?php echo $total;?></td>
 </tr>
</table>